package com.mikelouis.test.scala.proginscala.chapter28

/**
 * A point class whose equals method has the wrong type signature.
 *
 * problem is: equals method is not properly override, should be equals(other: Any)
 * Created by yuazhu on 2/26/2015.
 */
object Points1 {
  class Point(val x: Int, val y: Int) {
    // An utterly wrong definition of equals
    def equals(other: Point): Boolean =
      this.x == other.x && this.y == other.y
  }

  def main(args: Array[String]) {
    val p1, p2 = new Point(1, 2)
    val q = new Point(2, 3)
    println(p1 equals p2)
    println(p1 equals q)

    // problem happens when put points in collection
    val coll = scala.collection.mutable.HashSet(p1)
    println(coll contains p2)
  }
}
